﻿#ifndef TEXTBLOCK_H
#define TEXTBLOCK_H
#include <QStringList>
#include <QPainter>
#include <QPen>
#include <QFont>

namespace Qly
{
class TextBlock
{
public:
    TextBlock();
    ~TextBlock();
    void setFont(const QFont& font);
    void setPen(const QPen &pen) {m_pen = pen;}
    void setText(QString text);
    void setTextList(QStringList texts);
    void draw(QPainter &p);
    void draw(QPainter &p, double angle);
//    void setTopCenter(QPoint p); //暂时没有实现
//    void setBottomCenter(QPoint p);
    void moveTo(double x_pix, double y_pix, double x_um, double y_um );
    void moveTo(QPointF p_pix, QPointF p_um);
    void translate(QPointF offset_pix, QPointF offset_um);
    bool contains(QPoint q) const; // 一个点是否在文字区域
    QRect boundingRect() const;
    void anchorPoint(QPointF &anchorPoint_pix, QPointF &anchorPoint_um);
    QPointF anchorPoint() {return m_anchorPoint_pix;}
private:
    void updateBoundingRect();
    QPointF m_anchorPoint_um;
    QPointF m_anchorPoint_pix;
    QStringList m_texts;
    QList<QRect> m_textsRect;
    QFont m_font;
    QPen m_pen;
    QRect m_boundingRect;
};

inline bool TextBlock::contains(QPoint q) const
{
    return m_boundingRect.contains(q);
}

inline QRect TextBlock::boundingRect() const
{
    return m_boundingRect;
}

} //namespace Qly
#endif // TEXTBLOCK_H
